package com.dimples.common.monitor.entity;

import com.dimples.common.util.Arith;

import io.swagger.annotations.ApiModelProperty;
import lombok.Setter;

/**
 * 內存相关信息
 *
 * @author zhongyj <1126834403@qq.com><br/>
 * @date 2020/7/30
 */
@Setter
public class Mem {

    /**
     * 内存总量
     */
    @ApiModelProperty(value = "内存总量")
    private double total;

    /**
     * 已用内存
     */
    @ApiModelProperty(value = "已用内存")
    private double used;

    /**
     * 剩余内存
     */
    @ApiModelProperty(value = "剩余内存")
    private double free;

    /**
     * 内存使用率
     */
    @ApiModelProperty(value = "内存使用率")
    private double usage;

    public double getTotal() {
        return Arith.div(total, (1024 * 1024 * 1024), 2);
    }

    public double getUsed() {
        return Arith.div(used, (1024 * 1024 * 1024), 2);
    }

    public double getFree() {
        return Arith.div(free, (1024 * 1024 * 1024), 2);
    }

    public double getUsage() {
        return Arith.mul(Arith.div(used, total, 4), 100);
    }

}
